package yagoPolitician;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;

// index tac data
public class IndexTACHandler extends DefaultHandler {

				
	boolean isText=false;
	String wikititle;
	IndexTACWriter writer;
	
	public IndexTACHandler(IndexTACWriter writer){
		this.writer=writer;
	}
	
	public void startElement(String uri, String localName,String qName, Attributes attributes) throws SAXException {
		if (qName.equals("entity")){
			
			//System.out.println("Entity encounters");
			//System.out.println("Wikititle:"+attributes.getValue("wiki_title"));
			wikititle = attributes.getValue("wiki_title");
		}
		
		if( qName.equals("wiki_text")){
			isText = true;
			//System.out.println("Encouter text");
		}
		

	}
	

	public void endElement(String uri, String localName, String qName) throws SAXException {
 
		//System.out.println("End Element :" + qName);
 
	}
	public void characters(char ch[], int start, int length) throws SAXException {
		 
		if( isText==true ){
			isText = false;
			String textContent = new String(ch,start,length);
			this.writer.addDocument(wikititle, textContent);
			
			
		}
 
	}
				
		
	
}
